home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3647 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  61 lines

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: strings
  5. Date: Tue, 30 Jan 96 14:03:00 GMT
  6. Organization: none
  7. Message-ID: <823010580snz@genesis.demon.co.uk>
  8. References: <4eg9qj$1ut4@sp115.ocs.lsu.edu> <TANMOY.96Jan28104305@qcd.lanl.gov> <4ei9q3$fh1@nervous.pdb.sni.de>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4ei9q3$fh1@nervous.pdb.sni.de>
  15.            mollers.pad@sni.de "Josef Moellers" writes:
  16.  
  17. >In <TANMOY.96Jan28104305@qcd.lanl.gov> tanmoy@qcd.lanl.gov (Tanmoy
  18. > Bhattacharya) writes:
  19. >
  20. >>In article <4eg9qj$1ut4@sp115.ocs.lsu.edu> eenaya@unix1.sncc.lsu.edu
  21. >>(Pradeep Nayar) writes: 
  22. >><snip>
  23. >>   I saw this piece of code in a book somewhere.  
  24. >
  25. >>Throw away the book: immediately.
  26. >
  27. >>   char *str ;
  28. >
  29. >>   str = "hello world"[10] ;
  30. >
  31. >>   what does the second line do?
  32. >
  33. >>Nothing meaningful. In fact, the compiler must tell you that this is
  34. >>incorrect: otherwise put your compiler exactly in the same place where
  35. >>your book deserves to go :-)
  36. >
  37. >You _could_ be a little more precise:
  38. >Assuming this is C (of which I know something) and not C++ (of which I
  39. >know next to nothing), the only problem I see with the two lines quoted
  40. >above is the asterisk in the definition of "str". If you leave out the
  41. >asterisk, it's the declaration of a character and the assignment of the
  42. >letter 'd' to the character.
  43.  
  44. The the variable was called 'ch' I'd agree that was probably the intention.
  45. However it is called 'str' so it is more likely it is the following which
  46. looks even stranger!
  47.  
  48.    char *str ;
  49.  
  50.    str = &"hello world"[10] ;
  51.  
  52. or
  53.  
  54.    str = "hello world"+10 ;
  55.  
  56. -- 
  57. -----------------------------------------
  58. Lawrence Kirby | fred@genesis.demon.co.uk
  59. Wilts, England | 70734.126@compuserve.com
  60. -----------------------------------------
  61.